﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Digitalmes.Model.ProductionManagement;
using Digitalmes.Model;

namespace Digitalmes.ViewModel.ProductionManagement.ProdArchiveVMs
{
    public partial class ProdArchiveListVM : BasePagedListVM<ProdArchive_View, ProdArchiveSearcher>
    {
        
        protected override IEnumerable<IGridColumn<ProdArchive_View>> InitGridHeader()
        {
            return new List<GridColumn<ProdArchive_View>>{
                
                this.MakeGridHeader(x => x.ProdArchive_Sn).SetTitle(@Localizer["Page.追溯码"].Value),
                this.MakeGridHeader(x => x.ProdArchive_ProductId).SetTitle(@Localizer["Page.产品Id"].Value),
                this.MakeGridHeader(x => x.ProdArchive_ProductCode).SetTitle(@Localizer["Page.产品编码"].Value),
                this.MakeGridHeader(x => x.ProdArchive_Wo).SetTitle(@Localizer["Page.工单号"].Value),
                this.MakeGridHeader(x => x.ProdArchive_LineId).SetTitle(@Localizer["Page.产线Id"].Value),
                this.MakeGridHeader(x => x.ProdArchive_LineCode).SetTitle(@Localizer["Page.产线编号"].Value),
                this.MakeGridHeader(x => x.ProdArchive_OpId).SetTitle(@Localizer["Page.工位"].Value),
                this.MakeGridHeader(x => x.ProdArchive_OpCode).SetTitle(@Localizer["Page.工位编号"].Value),
                this.MakeGridHeader(x => x.ProdArchive_RoutingId).SetTitle(@Localizer["Page.工艺路线"].Value),
                this.MakeGridHeader(x => x.ProdArchive_RoutingCode).SetTitle(@Localizer["Page.工艺路线编号"].Value),
                this.MakeGridHeader(x => x.ProdArchive_InboundTime).SetTitle(@Localizer["Page.工位进站时间"].Value),
                this.MakeGridHeader(x => x.ProdArchive_Status).SetTitle(@Localizer["Page.状态"].Value),
                this.MakeGridHeader(x => x.ProdArchive_OutboundTime).SetTitle(@Localizer["Page.工位出站时间"].Value),
                this.MakeGridHeader(x => x.ProdArchive_Shift).SetTitle(@Localizer["Page.班次"].Value),
                this.MakeGridHeader(x => x.ProdArchive_CycleTime).SetTitle(@Localizer["Page.用时"].Value),
                this.MakeGridHeader(x => x.ProdArchive_CreateTime).SetTitle(@Localizer["_Admin.CreateTime"].Value),
                this.MakeGridHeader(x => x.ProdArchive_UpdateTime).SetTitle(@Localizer["_Admin.UpdateTime"].Value),
                this.MakeGridHeader(x => x.ProdArchive_CreateBy).SetTitle(@Localizer["_Admin.CreateBy"].Value),
                this.MakeGridHeader(x => x.ProdArchive_UpdateBy).SetTitle(@Localizer["_Admin.UpdateBy"].Value),
                this.MakeGridHeader(x => x.ProdArchive_IsValid).SetTitle(@Localizer["_Admin.IsValid"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<ProdArchive_View> GetSearchQuery()
        {
            var query = DC.Set<ProductionArchive>()
                
                .CheckContain(Searcher.Sn, x=>x.Sn)
                .CheckEqual(Searcher.ProductId, x=>x.ProductId)
                .CheckContain(Searcher.ProductCode, x=>x.ProductCode)
                .CheckContain(Searcher.Wo, x=>x.Wo)
                .CheckEqual(Searcher.LineId, x=>x.LineId)
                .CheckContain(Searcher.LineCode, x=>x.LineCode)
                .CheckEqual(Searcher.OpId, x=>x.OpId)
                .CheckContain(Searcher.OpCode, x=>x.OpCode)
                .CheckEqual(Searcher.RoutingId, x=>x.RoutingId)
                .CheckContain(Searcher.RoutingCode, x=>x.RoutingCode)
                .CheckBetween(Searcher.InboundTime?.GetStartTime(), Searcher.InboundTime?.GetEndTime(), x => x.InboundTime, includeMax: false)
                .CheckEqual(Searcher.Status, x=>x.Status)
                .CheckBetween(Searcher.OutboundTime?.GetStartTime(), Searcher.OutboundTime?.GetEndTime(), x => x.OutboundTime, includeMax: false)
                .CheckContain(Searcher.Shift, x=>x.Shift)
                .CheckEqual(Searcher.CycleTime, x=>x.CycleTime)
                .CheckBetween(Searcher.CreateTime?.GetStartTime(), Searcher.CreateTime?.GetEndTime(), x => x.CreateTime, includeMax: false)
                .CheckBetween(Searcher.UpdateTime?.GetStartTime(), Searcher.UpdateTime?.GetEndTime(), x => x.UpdateTime, includeMax: false)
                .CheckContain(Searcher.CreateBy, x=>x.CreateBy)
                .CheckContain(Searcher.UpdateBy, x=>x.UpdateBy)
                .Select(x => new ProdArchive_View
                {
				    ID = x.ID,
                    
                    ProdArchive_Sn = x.Sn,
                    ProdArchive_ProductId = x.ProductId,
                    ProdArchive_ProductCode = x.ProductCode,
                    ProdArchive_Wo = x.Wo,
                    ProdArchive_LineId = x.LineId,
                    ProdArchive_LineCode = x.LineCode,
                    ProdArchive_OpId = x.OpId,
                    ProdArchive_OpCode = x.OpCode,
                    ProdArchive_RoutingId = x.RoutingId,
                    ProdArchive_RoutingCode = x.RoutingCode,
                    ProdArchive_InboundTime = x.InboundTime,
                    ProdArchive_Status = x.Status,
                    ProdArchive_OutboundTime = x.OutboundTime,
                    ProdArchive_Shift = x.Shift,
                    ProdArchive_CycleTime = x.CycleTime,
                    ProdArchive_CreateTime = x.CreateTime,
                    ProdArchive_UpdateTime = x.UpdateTime,
                    ProdArchive_CreateBy = x.CreateBy,
                    ProdArchive_UpdateBy = x.UpdateBy,
                    ProdArchive_IsValid = x.IsValid,
                })
                .OrderBy(x => x.ID);
            return query;
        }

        
    }
    public class ProdArchive_View: ProductionArchive
    {
        
        public string ProdArchive_Sn { get; set; }
        public long? ProdArchive_ProductId { get; set; }
        public string ProdArchive_ProductCode { get; set; }
        public string ProdArchive_Wo { get; set; }
        public long? ProdArchive_LineId { get; set; }
        public string ProdArchive_LineCode { get; set; }
        public long? ProdArchive_OpId { get; set; }
        public string ProdArchive_OpCode { get; set; }
        public long? ProdArchive_RoutingId { get; set; }
        public string ProdArchive_RoutingCode { get; set; }
        public DateTime? ProdArchive_InboundTime { get; set; }
        public SnStatusEnum? ProdArchive_Status { get; set; }
        public DateTime? ProdArchive_OutboundTime { get; set; }
        public string ProdArchive_Shift { get; set; }
        public decimal? ProdArchive_CycleTime { get; set; }
        public DateTime? ProdArchive_CreateTime { get; set; }
        public DateTime? ProdArchive_UpdateTime { get; set; }
        public string ProdArchive_CreateBy { get; set; }
        public string ProdArchive_UpdateBy { get; set; }
        public bool ProdArchive_IsValid { get; set; }

    }

}